//
//  MBSpaceContactViewController.m
//  MiBaoTu
//
//  Created by admin on 16/9/26.
//  Copyright © 2016年 com.caesartech15. All rights reserved.
//

#import "MBSpaceContactViewController.h"

@interface MBSpaceContactViewController ()<UITableViewDataSource,UITableViewDelegate> {
    UITableView                     *_tableView;
}

@end

@implementation MBSpaceContactViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setTitleView:@"联系我们"];
    [self setBackItem];
    
    [self onCreateUI];
}

#pragma mark - UI
- (void)onCreateUI
{
    _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, self.view.height) style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _tableView.backgroundColor = [UIColor clearColor];
    _tableView.backgroundView = nil;
    [self.view addSubview:_tableView];
    if (ISIPAD) {
        _tableView .tableHeaderView = [self addTableHeadView];
    }
}

- (void)onUpdateUIForView:(UIDeviceOrientation)orientation
{
    _tableView.frame = CGRectMake(0, 0, SCREEN_WIDTH, self.view.height);
    if (ISIPAD) {
        _tableView .tableHeaderView = [self addTableHeadView];
    }
    [_tableView reloadData];
}

- (UIView *)addTableHeadView
{
    UIView *bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 20*PERCEN)];
    bgView.backgroundColor = [UIColor clearColor];
    return bgView;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - UITableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 4;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //歌曲
    static NSString *cellID = @"space_about_Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        UILabel *_nickNameLb = [[UILabel alloc]initWithFrame:CGRectMake(25*PERCEN, (100*PERCEN-20)/2., 80, 20)];
        _nickNameLb.backgroundColor = [UIColor clearColor];
        _nickNameLb.textAlignment = NSTextAlignmentLeft;
        _nickNameLb.textColor = UIColorFromHex(0x333333);
        _nickNameLb.font = [UIFont systemFontOfSize:13.f];
        _nickNameLb.tag = 1400;
        [cell.contentView addSubview:_nickNameLb];
        
        UILabel *_contentNameLb = [[UILabel alloc]initWithFrame:CGRectMake(_nickNameLb.right+38*PERCEN, (100*PERCEN-20)/2., 270, 20)];
        _contentNameLb.backgroundColor = [UIColor clearColor];
        _contentNameLb.textAlignment = NSTextAlignmentLeft;
        _contentNameLb.textColor = UIColorFromHex(0x333333);
        _contentNameLb.font = [UIFont systemFontOfSize:13.f];
        _contentNameLb.tag = 1401;
        [cell.contentView addSubview:_contentNameLb];
        
        UIView *_lineView = [[UIView alloc]initWithFrame:CGRectMake(0, 100*PERCEN-1, SCREEN_WIDTH, 1)];
        _lineView.backgroundColor = [UIColorFromHex(0xcccccc) colorWithAlphaComponent:.35];
        _lineView.tag = 1402;
        [cell.contentView addSubview:_lineView];
    }
    
    UILabel *nickNameLb = (UILabel *)[cell viewWithTag:1400];
    UILabel *contentNameLb = (UILabel *)[cell viewWithTag:1401];
    UIView *lineView = (UIView *)[cell viewWithTag:1402];
    
    if (indexPath.row == 0) {
        nickNameLb.text = @"微信公众号";
        contentNameLb.text = @"米宝兔mibokids（MBTbaby）";
    }
    else if (indexPath.row == 1) {
        nickNameLb.text = @"微信个人号";
        contentNameLb.text = @"米宝兔母婴）（mibokids-）";
    }
    else if (indexPath.row == 2) {
        nickNameLb.text = @"售后电话";
        contentNameLb.text = @"4001-853-155";
    }
    else if (indexPath.row == 3) {
        nickNameLb.text = @"地址";
        contentNameLb.text = @"上海市嘉定区金沙江路3131号创意园8号楼104";
        lineView.hidden = YES;
    }
    float itemWidth = [nickNameLb.text boundingRectWithSize:CGSizeMake(1000, 20) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:nickNameLb.font} context:NULL].size.width+4;
    nickNameLb.width = itemWidth;
    contentNameLb.left = nickNameLb.right+30*PERCEN;
    
    if (ISIPAD) {
        nickNameLb.left = 460*PERCEN*(self.orientation==UIDeviceOrientationPortrait?1.0*SCREEN_WIDTH/SCREEN_HEIGHT:1.);
        contentNameLb.left = nickNameLb.right+38*PERCEN;
        lineView.frame = CGRectMake(440*PERCEN*(self.orientation==UIDeviceOrientationPortrait?1.0*SCREEN_WIDTH/SCREEN_HEIGHT:1.), 100*PERCEN-1, SCREEN_WIDTH-880*PERCEN*(self.orientation==UIDeviceOrientationPortrait?1.0*SCREEN_WIDTH/SCREEN_HEIGHT:1.), 1);
    }
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 100*PERCEN;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    
}

@end
